package com.kgc.storeconsumer.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.store.pojo.OutStore;
import com.kgc.store.pojo.Quality;
import com.kgc.storeconsumer.feign.OutStoreFeign;
import com.kgc.storeconsumer.feign.QualityFeign;
import com.kgc.storeconsumer.feign.QualityWorkFlowFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin("*")
@RequestMapping("/quality")
public class QualityController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private QualityFeign qualityFeign;

    @Autowired
    private QualityWorkFlowFeign qualityWorkFlowFeign;

    @RequestMapping("getQualityList")
    @ResponseBody
    public ResponseMsg getQualityList(@RequestBody Map<String, Object> map){
        logger.info("QualityController getQualityList map:"+map);
        ResponseMsg msg =qualityFeign.getQualityList(map);
        logger.debug("QualityController getQualityList msg:"+msg);
        return msg;
    }

    @RequestMapping("delQuality")
    @ResponseBody
    public ResponseMsg delQuality(String code){
        logger.info("QualityController delQuality code:"+code);
        ResponseMsg msg =qualityFeign.delQuality(code);
        logger.debug("QualityController delQuality msg:"+msg);
        return msg;
    }

    @RequestMapping("addQuality")
    @ResponseBody
    ResponseMsg addQuality(@RequestBody Quality quality){
        logger.info("QualityController addQuality quality:"+quality);
        ResponseMsg msg =qualityFeign.addQuality(quality);
        logger.debug("QualityController addQuality msg:"+msg);
        return msg;
    }

    @RequestMapping("selectQualityType")
    @ResponseBody
    public ResponseMsg selectQualityType(){
        logger.info("QualityController selectQualityType is start...");
        ResponseMsg msg =qualityFeign.selectQualityType();
        logger.debug("QualityController selectQualityType msg:"+msg);
        return msg;
    }

    @RequestMapping("check")
    @ResponseBody
    ResponseMsg check(@RequestBody Map<String,Object> map){
        ResponseMsg responseMsg = new ResponseMsg();
        logger.info("QualityController check params,{}",map.toString());
        Map<String,Object> variables = new HashMap<>();
        variables.put("code",(String) map.get("code"));//单据编号
        variables.put("checkManId",(Integer) map.get("checkManId"));//审批人
        variables.put("checkManName",(String) map.get("checkManName"));//审批人
        variables.put("checkComment",(String) map.get("checkComment"));//审批意见
        variables.put("checkDate",new Date());//审批时间
        variables.put("checkRes",(boolean)map.get("checkRes"));//审批结果
        com.kgc.activiti.util.ResponseMsg msg=  qualityWorkFlowFeign.competeTask(variables);
        responseMsg.setCode(msg.getCode());
        responseMsg.setMsg(msg.getMsg());
        return responseMsg;
    }

    @RequestMapping("selectQualityDetailByCGDD")
    @ResponseBody
    ResponseMsg selectQualityDetailByCGDD(@RequestParam("cgddCode") String cgddCode){
        logger.info("QualityController selectQualityDetailByCGDD cgddCode:"+cgddCode);
        ResponseMsg msg =qualityFeign.selectQualityDetailByCGDD(cgddCode);
        logger.debug("QualityController selectQualityDetailByCGDD msg:"+msg);
        return msg;
    }

}
